package com.bsoft.gol.hbs.dao;

import org.atag.dao.action.QoHibernateStatelessResultAction;
import ctd.persistence.annotation.DAOMethod;
import ctd.persistence.annotation.DAOParam;
import ctd.persistence.support.hibernate.HibernateSupportDelegateDAO;
import ctd.persistence.support.hibernate.template.HibernateSessionTemplate;
import pcn.bean.hpi.PcnHpiType;
import pcn.bean.sign.PcnHpiTypeQo;

import java.util.List;

public abstract class PcnHpiTypeDAO extends HibernateSupportDelegateDAO<PcnHpiType> {

	public PcnHpiTypeDAO() {
		this.setKeyField("typeId");
	}

	@DAOMethod(sql = "from PcnHpiType where typeId=:typeId")
	public abstract PcnHpiType getPcnHpiTypeById(@DAOParam("typeId") int typeId);

	@DAOMethod(sql = "from PcnHpiType where typeCode=:typeCode")
	public abstract PcnHpiType getPcnHpiTypeByCode(@DAOParam("typeCode") String typeCode);

	@DAOMethod(sql = "from PcnHpiType")
	public abstract List<PcnHpiType> findPcnHpiTypes();

	/**
	 * 删除健康指标类型
	 * @param typeId
	 */
	@DAOMethod(sql = "delete PcnHpiType where typeId=:typeId ")
	public abstract void updateBaseHpiType(@DAOParam("typeId") int typeId);

	public List<PcnHpiType> page(PcnHpiTypeQo qo) {

		QoHibernateStatelessResultAction<PcnHpiType, PcnHpiTypeQo> action = new QoHibernateStatelessResultAction(true, qo, PcnHpiType.class);
		action.setSql("SELECT * FROM pcn_hpi_type where 1=1");
		action.addCondition("and tenant_id like :tenantId");
		action.addCondition("and type_code = :typeCode");

		HibernateSessionTemplate.instance().execute(action);
		return action.getResultList();
	}
}
